package flowise.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.google.common.collect.Lists;
import flowise.entity.NodeOutputsValue;
import flowise.entity.NodeParams;
import flowise.service.INode;
import flowise.utils.Utils;

import java.util.List;

/**
 * @author huangya
 * @date 2024/1/28
 */
public class ConversationalRetrievalQAChain_Chains extends INode {
    private String label;
    private String name;
    private Integer version;
    private String type;
    private String icon;
    private String category;
    private List<String> baseClasses;
    private String description;
    private List<NodeParams> inputs;
    private List<NodeOutputsValue> outputs;


    ConversationalRetrievalQAChain_Chains() {
        this.label = "Conversational Retrieval QA Chain";
        this.name = "conversationalRetrievalQAChain";
        this.version = 1;
        this.type = "ConversationalRetrievalQAChain";
        this.icon = "qa.svg";
        this.category = "Chains";
        this.description = "Document QA - built on RetrievalQAChain to provide a chat history component";
        this.baseClasses = Lists.newArrayList(type);
        baseClasses.addAll(Utils.getBaseClasses(ConversationalRetrievalQAChain_Chains.class));

        String inputsStr = "[\n" +
                "\t{\n" +
                "\t\t\"label\": \"Language Model\",\n" +
                "\t\t\"name\": \"model\",\n" +
                "\t\t\"type\": \"BaseLanguageModel\"\n" +
                "\t},\n" +
                "\t{\n" +
                "\t\t\"label\": \"Vector Store Retriever\",\n" +
                "\t\t\"name\": \"vectorStoreRetriever\",\n" +
                "\t\t\"type\": \"BaseRetriever\"\n" +
                "\t},\n" +
                "\t{\n" +
                "\t\t\"label\": \"Memory\",\n" +
                "\t\t\"name\": \"memory\",\n" +
                "\t\t\"type\": \"BaseMemory\",\n" +
                "\t\t\"optional\": true,\n" +
                "\t\t\"description\": \"If left empty, a default BufferMemory will be used\"\n" +
                "\t},\n" +
                "\t{\n" +
                "\t\t\"label\": \"Return Source Documents\",\n" +
                "\t\t\"name\": \"returnSourceDocuments\",\n" +
                "\t\t\"type\": \"boolean\",\n" +
                "\t\t\"optional\": true\n" +
                "\t},\n" +
                "\t{\n" +
                "\t\t\"label\": \"System Message\",\n" +
                "\t\t\"name\": \"systemMessagePrompt\",\n" +
                "\t\t\"type\": \"string\",\n" +
                "\t\t\"rows\": 4,\n" +
                "\t\t\"additionalParams\": true,\n" +
                "\t\t\"optional\": true,\n" +
                "\t\t\"placeholder\": \"I want you to act as a document that I am having a conversation with. Your name is \\\"AI Assistant\\\". You will provide me with answers from the given info. If the answer is not included, say exactly \\\"Hmm, I am not sure.\\\" and stop after that. Refuse to answer any question not about the info. Never break character.\"\n" +
                "\t},\n" +
                "\t{\n" +
                "\t\t\"label\": \"Chain Option\",\n" +
                "\t\t\"name\": \"chainOption\",\n" +
                "\t\t\"type\": \"options\",\n" +
                "\t\t\"options\": [\n" +
                "\t\t\t{\n" +
                "\t\t\t\t\"label\": \"MapReduceDocumentsChain\",\n" +
                "\t\t\t\t\"name\": \"map_reduce\",\n" +
                "\t\t\t\t\"description\": \"Suitable for QA tasks over larger documents and can run the preprocessing step in parallel, reducing the running time\"\n" +
                "\t\t\t},\n" +
                "\t\t\t{\n" +
                "\t\t\t\t\"label\": \"RefineDocumentsChain\",\n" +
                "\t\t\t\t\"name\": \"refine\",\n" +
                "\t\t\t\t\"description\": \"Suitable for QA tasks over a large number of documents.\"\n" +
                "\t\t\t},\n" +
                "\t\t\t{\n" +
                "\t\t\t\t\"label\": \"StuffDocumentsChain\",\n" +
                "\t\t\t\t\"name\": \"stuff\",\n" +
                "\t\t\t\t\"description\": \"Suitable for QA tasks over a small number of documents.\"\n" +
                "\t\t\t}\n" +
                "\t\t],\n" +
                "\t\t\"additionalParams\": true,\n" +
                "\t\t\"optional\": true\n" +
                "\t}\n" +
                "]";
        this.inputs = JSON.parseObject(inputsStr, new TypeReference<List<NodeParams>>(){});
    }

}